<script>
    layui.config({
        base: '/static/customAdmin/'
    }).extend({
        index: 'lib/index'
    }).use([ 'index','admin','upload',"laypage"], async () => {
        const upload = layui.upload,admin = layui.admin, $ = layui.$;

        $("#company_search").on('keydown', function (e) {
            let eCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
            if (eCode === 13) {
                self.location.href = "@{{ urlfor "HandBookController.Index"}}" + "?searchWord=" + $(this).val();
            }
        });

        $(".is_list_delete").on('click', function (e) {
            layer.confirm('真的删除么', {title: '提示'}, async (index) => {
                await admin.delete(`/handbook/delete/` +$(this).data('id'), e);
                layer.close(index);
                self.location.reload()
            });
        });

        const handbook_account_upload = upload.render({
            elem: '#handbook_account_upload'
            , url: '/handbook/import/2'
            , accept: 'file'
            , field: 'filename'
            , before: function (obj) {
                layer.load(2);
            }
            , done: function (res) {
                if (res.status) {
                    layer.msg(res.msg, {
                        offset: '15px'
                        , icon: 1
                        , time: 2000
                        , id: 'Message'
                    });
                } else {
                    layer.msg(res.msg, {
                        offset: '15px'
                        , icon: 2
                        , time: 2000
                        , id: 'Message'
                    });
                }

                layer.closeAll('loading');
            }
            , error: function () {
                layer.closeAll('loading');
            }
        });

        const handbook_manual_upload = upload.render({
            elem: '#handbook_manual_upload'
            , url: '/handbook/import/1'
            , accept: 'file'
            , field: 'filename'
            , before: function (obj) {
                layer.load(2);
            }
            , done: function (res) {
                if (res.status) {
                    layer.msg(res.msg, {
                        offset: '15px'
                        , icon: 1
                        , time: 2000
                        , id: 'Message'
                    });
                } else {
                    layer.msg(res.msg, {
                        offset: '15px'
                        , icon: 2
                        , time: 2000
                        , id: 'Message'
                    });
                }

                layer.closeAll('loading');
            }
            , error: function () {
                layer.closeAll('loading');
            }
        });
    });
</script>